package com.kokuma.drawsprite.common;

import java.sql.Timestamp;
import java.util.Date;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class SNFactory {

	private static byte[] by = new byte[0];
	private static int count = 0;

	/**
	 * 获取组合为一字符串，一般用于显示流水或done_code
	 * 
	 * @param regionId
	 *            地市编码
	 * @param module
	 *            业务模块编号
	 * @param sequenceTableName
	 *            序列表名称
	 * @param numlen
	 *            序列数字长度
	 * @return 地市编码 + 时间(yyyymmddhhmmss) + 业务模块编号 + 指定长度的数字序列
	 * @throws Exception
	 */
	public static synchronized String generatorUnionCode(String busi,
			String module, int numlen) {
		if (count >= Integer.MAX_VALUE) {
			count = 0;
		}
		StringBuffer buffer = new StringBuffer();
		buffer.append(busi);
		Date d = new Date();
		buffer.append(DateTimeUtil.DATA_FORMAT_YYYYMMDDHHMMSS.format(d));
		buffer.append(module);
		String tmpStr = String.valueOf(count++);
		int len = numlen - tmpStr.length();
		if (len > 0) {
			while (len > 0) {
				buffer.append("0");
				len = len - 1;
			}
		} else {
			tmpStr = tmpStr.substring(0, numlen);
		}
		buffer.append(tmpStr);
		return buffer.toString();
	}

	public static String getPicDoneCode() {
		return generatorUnionCode("P", "X", 6);
	}
	
	public static String getPaintDoneCode() {
		return generatorUnionCode("U", "X", 6);
	}


	public static void main(String[] args) throws Exception {
		try {
			for (int i = 0; i < 10; i++)
				System.out.println(getPicDoneCode());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
